package com.example.demo.controller;

import com.example.demo.entity.RoleFunction;
import com.example.demo.service.FunctionService;
import com.example.demo.utils.LayuiJson;
import com.example.demo.utils.R;
import com.example.demo.utils.ReSet;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class FunctionController {
    @Resource
    private FunctionService fs;

    /**
     * 查询用户功能
     * */
    @PostMapping("selectfunction")
    @ResponseBody
    public R selectfunction(String user_email){
        List list = fs.selfunc(user_email);
//        Map<String,Object> map = new HashMap<>();
//        map.put("code",1);
//        map.put("msg","成功");
//        map.put("data",list);
//        map.put("count",200);

//        return map;
        return ReSet.Ok(list);
    }
    /**
     * 查询角色功能
     * */
        @PostMapping("selrolefunc")
    public R selrolefunc(Integer rid){
        List list = fs.selrolefunc(rid);

        return ReSet.Ok(list);

    }
    /**
     * 更改角色功能权限
     * */
    @PostMapping("updatefuncstatus")
    public R updatefuncstatus(Integer pty,Integer fid){
        int i = fs.upfunc(pty, fid);
        if (i > 0){
            return ReSet.Ok(i);
        }
        return ReSet.Err();
    }
    /**
     * 增加功能
     * */
    @PostMapping("insertfunction")
    public R insertfunction(String function_name, String function_address, Integer role_id){
        int i = fs.infunc(function_name,function_address,role_id);
        if (i > 0){
            return ReSet.Ok(i);
        }
        return ReSet.Err();
    }
}
